

const util = require('../../utils/util.js');
const urlMap1 = {
  "9bc4785d7547016e79ee3d917eccd578": '0',//居家育儿
  "c9dd76b3ef0c21fd5f55c23fb27330ef": '0',//家务料理
  "cc0aef8db8eea1afa7d63f5aa6254ad2": '0',//居家养老
  "97371c2ce41f257ada717c0f15566817": '0',//母婴护理
  "e48dbadb859c3184f56cd550a85d7265": '0',//居家保洁
  "3c63d1026457b886b2208cf506a21df0": '0',//整理收纳
  "79e8c60dcad6b82d5bb1965245f42983": '0',//专属管家
  "0303baea961f83787616eadf373d5e3a": '0',//宠物服务
  "7c52410ecf493f2fccea7ae090815885": '0',//家宴私厨
  "20c8caa1046ae26939d2af517a5433c9": '0',//综合服务
  "a547da6a560491d49f3c452353d06223": '0',//政企服务
  "b546262b1eb09cbaa69bca4ab9213fca": '0',//家居洗护
  "9932ec2d6171a0ddcec1955202eab33c": '0',//陪诊服务
  "666c5bd20b017090fd6cd2670a0af10d": '0',//更多
}

const urlMap2 = {
  "9bc4785d7547016e79ee3d917eccd578": '/page2/jiadianqingxi/index',//家电清洗
  "3c7b4bb5b9b3640c51b7ed9c1a01ac55": '/page2/jiadianweixiu/index',//家电维修
  "ec210c8e72a3008591460f1a5f7b922d": '/page2/guandaoshutong/index',//管道疏通
  "b461892c54852b45bfb2ff9c83b1feae": '/page2/shangmenkaisuo/index',//上门开锁
  "d820f49944022aafe8b76ae6b6ef9fde": '/page2/shuidianweixiu/index',//水电维修
  "47faa8e11b7d97b17447c27acf4ff577": '/page2/dibandala/index',//地板打蜡
  "5eb81a62f54fb111b4dcda6aa43a2591": '/page2/pijubaoyang/index',//皮具保养
  "bbc9ffbb72c7bb0b58af2ffa5dcff454": '/page2/hehuoren/index',//合伙人
}
Page({
  data: {
    imagesBaseUrl: util.imagesBaseUrl,

    selectIndex: 0,
    showImage: false,
    menuList: [
      {
        id: 0,
        name: '居家育儿',
        label: ''
      },
      {
        id: 1,
        name: '家务料理',
        label: ''
      },
      {
        id: 2,
        name: '居家养老',
        label: ''
      },
      {
        id: 3,
        name: '母婴护理',
        label: ''
      },
      {
        id: 4,
        name: '居家保洁',
        label: ''
      },
      {
        id: 5,
        name: '整理收纳',
        label: ''
      },
      {
        id: 6,
        name: '尊享服务',
        label: ''
      },
      // {
      //   id: 7,
      //   name: '家庭后勤',
      //   label: ''
      // },
      {
        id: 8,
        name: '宠物服务',
        label: ''
      },
      {
        id: 9,
        name: '家厨私宴',
        label: ''
      },
      {
        id: 10,
        name: '综合服务',
        label: ''
      },
      {
        id: 11,
        name: '政企服务',
        label: ''
      },
    ],
    menuList2Flag: false,
    menuList2: [
    ],
    active: 0,
    activeKey: 0,
    inputValue: '',
    selectItemTitleImage: ''
  },
  getInit(selectId) {
    this.setData({
      menuList: []
    })
    util.https('categoriesMgmt/categoriesQry', {
      "pid": "1"
    }, (res) => {
      console.log(res)
      let i = 0;
      res.categoriesBoList.forEach((item, index) => {
        if (item.id == selectId) {
          i = index
        }
      })
      this.setData({
        menuList: res.categoriesBoList,
        selectIndex: res.categoriesBoList[i].id,
        selectItemTitleImage: res.categoriesBoList[i].images,
        showImage: res.categoriesBoList[i].type === 0 ? true : false
      });
      this.getInit2(res.categoriesBoList[i].id)
    }, (res) => {
      console.log(res)
      wx.showModal({
        title: '温馨提示',
        content: res.errorMsg,
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
    })
  },
  getInit2(id) {
    util.https('serviceInfoMgmt/serviceInfoQry', {
      "categoryId": id,
    }, (res) => {
      console.log(res)
      console.log(res.serviceInfoBos)
      console.log(res.serviceInfoBos.length)
      if (res.serviceInfoBos.length == 0) {
        this.setData({
          menuList2Flag: false
        })
      } else {
        this.setData({
          menuList2: res.serviceInfoBos,
          menuList2Flag: true
        });
      }
    }, (res) => {
      console.log(res)
      wx.showModal({
        title: '温馨提示',
        content: res.errorMsg,
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
    })
  },
  doSearch() {
    if (!this.data.inputValue) {
      return
    }
    this.setData({
      menuList2: [],
      selectIndex: 0
    })
    util.https('serviceInfoMgmt/serviceInfoQry', {
      name: this.data.inputValue
    }, (res) => {
      console.log(res)
      if (res.serviceInfoBos.length == 0) {
        this.setData({
          menuList2Flag: false
        })
      } else {
        this.setData({
          menuList2: res.serviceInfoBos,
          menuList2Flag: true,
          selectItemTitleImage: ''
        });
      }
      // let menuList2 = res.serviceInfoBos;
      // this.setData({
      //   menuList2: menuList2,
      //   selectItemTitleImage: ''
      // });
    }, (res) => {
      console.log(res)
      wx.showModal({
        title: '温馨提示',
        content: res.errorMsg,
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
    })
  },
  onShow() {
    wx.setStorageSync('address_get', '')
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      })
    };
    let fenleiSearchInputType = wx.getStorageSync('fenleiSearchInputType');
    if (fenleiSearchInputType === '1') {
      wx.setStorageSync('fenleiSearchInputType', '');
      let fenleiSearchInput = wx.getStorageSync('fenleiSearchInput');
      this.setData({
        inputValue: fenleiSearchInput
      });
      this.doSearch();
    } else {
      let hometofenleiId = wx.getStorageSync('hometofenlei');
      // console.log(hometofenleiType)
      // this.setData({
      //   mIndex: hometofenleiType ? parseInt(hometofenleiType) : 0
      // });
      let hometofenleiId2 = hometofenleiId ? hometofenleiId : '9bc4785d7547016e79ee3d917eccd578'
      this.getInit(hometofenleiId2);
    }

  },
  onLoad() {
  },
  clickTab(e) {
    const data = e.currentTarget.dataset;
    console.log(data)
    if (this.data.selectIndex == data.item.id) {
      return
    }
    wx.setStorageSync('hometofenlei', data.item.id);
    this.setData({
      menuList2: [],
      selectIndex: data.item.id,
      selectItemTitleImage: data.item.images,
      showImage: data.item.type === 0 ? true : false
    });
    this.getInit2(data.item.id)
  },
  clickItem2(e) {
    const s = e.currentTarget.dataset;
    console.log(s)
    wx.setStorageSync('fenlei_yuyue', s.item);
    const url = urlMap2[s.item.id]
    if (url) {
      wx.navigateGo({ url: url })
    } else {
      wx.navigateTo({ url: '/page2/yuyue/index?id=' + s.item.id })
    }
  },
  clickItem1(e) {
    const s = e.currentTarget.dataset;
    wx.setStorageSync('fenlei_yuyue', s.item)
    const url = urlMap2[s.item.id]
    if (url) {
      wx.navigateGo({ url: url })
    } else {
      wx.navigateTo({ url: '/page2/yuyue/index?id=' + s.item.id })
    }
  },
  onShareAppMessage() {

  },
})
